package com.chinacoal.microservice.config;

import com.chinacoal.microservice.Interceptor.CcmsAuthenticationInterceptor;
import com.chinacoal.microservice.Interceptor.WechatAuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zhuliang
 * @version V1.0
 * @Description: 拦截器配置类
 * @date 2020-12-28 13：48
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //微信公众号token验证拦截器
        registry.addInterceptor(wechatAuthenticationInterceptor())
                .addPathPatterns("/wechat/**", "/wechatOfficialAccount/**");

        //网页token验证拦截器
        registry.addInterceptor(ccmsAuthenticationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/wechat/**", "/wechatOfficialAccount/**");
    }

    @Bean
    public WechatAuthenticationInterceptor wechatAuthenticationInterceptor() {
        return new WechatAuthenticationInterceptor();
    }

    @Bean
    public CcmsAuthenticationInterceptor ccmsAuthenticationInterceptor() {
        return new CcmsAuthenticationInterceptor();
    }
}
